<?php

namespace App\Admin\Models;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{

    protected $table = 'admin_roles';
    protected $guarded = [];

    public function users()
    {
        return $this->belongsToMany(User::class, 'user_roles');
    }

    public function permissions()
    {
        return $this->belongsToMany(Permission::class);
    }

    /*
     * 添加角色
     * @author turtle
     * create_time 2017-01-02
     */

    public static function addRole($role) {
        $role['created_at'] = date('Y-m-d H:m:s');
        $role['updated_at'] = date('Y-m-d H:m:s');
        return self::insertGetId($role);
    }

    /*
     * 更新角色
     * @author turtle
     * create_time 2017-01-03
     */

    public static function editRole($role, $role_id) {
        $role['updated_at'] = date('Y-m-d H:m:s');
        return self::where('id', $role_id)->update($role);
    }
}
